﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using YFIN.Data;

namespace YFIN.Helper.Extension
{
    public static class YFINExtension
    {
        public static void Go(Action<YFIN_DBEntities> todo)
        {
            using (var entities = new YFIN_DBEntities())
            {
                todo(entities);
            }
        }

        public static void GoAndSave(Action<YFIN_DBEntities> todo)
        {
            using (var entities = new YFIN_DBEntities())
            {
                todo(entities);
                entities.SaveChanges();
            }
        }

        public static T Go<T>(Func<YFIN_DBEntities, T> todo)
        {
            using(var entities = new YFIN_DBEntities())
            {
                return todo(entities);
            }
        }

        public static T GoAndSave<T>(Func<YFIN_DBEntities, T> todo)
        {
            using (var entities = new YFIN_DBEntities())
            {
                var res = todo(entities);
                entities.SaveChanges();
                return res;
            }
        }
    }
}
